
import com.ifunpay.util.bean.ApplicationConfig;
import lombok.extern.log4j.Log4j2;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by dongyuncong on 2017/7/28.
 */
@Log4j2
public class JDBC {
    static String url = "jdbc:mysql://172.22.23.210/yilin_test?useUnicode=true";
    static String user = "root";
    static String password = "samething";
    static String driverClass = "com.mysql.jdbc.Driver";


    public static Connection getConnection() {

        try {

            Class.forName(driverClass);
        } catch (Exception e) {
            log.info("驱程程序注册出错: ", e);
            System.out.println("驱程程序注册出错"+e.getMessage());
        }

        try {
            Connection conn = DriverManager.getConnection(url, user, password);
            log.info("conn-----", conn);
            return conn;
        } catch (SQLException e) {
            log.info(e);
            // e.printStackTrace();
            throw new RuntimeException("e----", e);
        }
    }


    public static void close(Connection conn, Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                log.info("jdbc-close-exception: ", e);
            }
        }
    }

    public static void close(Connection conn, Statement stmt, ResultSet rs) {
        if (rs != null)
            try {
                rs.close();
            } catch (SQLException e1) {
                e1.printStackTrace();
                throw new RuntimeException(e1);
            }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                log.info("jdbc-close-exception: ", e);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                log.info("jdbc-close-exception: ", e);
            }
        }
    }

    @Test
    public void add() throws Exception{
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;

        for (int i = 0;i<10000;i++){
            Calendar now = Calendar.getInstance();
            now.add(Calendar.DAY_OF_MONTH, 6);
            now.set(Calendar.HOUR_OF_DAY, 23);
            now.set(Calendar.MINUTE, 59);
            now.set(Calendar.SECOND, 59);
            /*
            try {
                conn = getConnection();
                String sql = "INSERT INTO test(time) VALUES(?) ";
                stmt = conn.prepareStatement(sql);
                stmt.setObject(1,now.getTime());
                int count = stmt.executeUpdate();
                log.info(count);

            } catch (Exception e) {
                System.out.println(e);
            }*/
        }
    }
}
